﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Hospital.Model.Page;
using SqlSugar;

namespace Hospital.IRepository
{
    //TEntiry是泛型，这个泛型是个带构造函数的class
    public interface IBaseRepository<TEntiry> where TEntiry : class, new()
    {
        /// <summary>
        /// 数据插入
        /// </summary>
        /// <param name="entiry"></param>
        /// <returns></returns>
        Task<bool> CreateAsync(TEntiry entiry);
        /// <summary>
        /// 根据id删除指定数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<bool> DeleteAsync(int id);
        Task<int> DeleteAsync(List<int> ints);
        /// <summary>
        /// 编辑数据
        /// </summary>
        /// <param name="entiry"></param>
        /// <returns></returns>
        Task<bool> EditAsync(TEntiry entiry);
        Task<int> EditAsync(TEntiry entiry, Expression<Func<TEntiry, bool>> func);
        /// <summary>
        /// 自定义修改字段
        /// </summary>
        /// <param name="columns"></param>
        /// <param name="func"></param>
        /// <returns></returns>
        Task<bool> EditAsync(Expression<Func<TEntiry, TEntiry>> columns, Expression<Func<TEntiry, bool>> func);
        /// <summary>
        /// 指定字段更新
        /// </summary>
        /// <param name="func">更新的字段</param>
        /// <param name="func">条件</param>
        /// <returns></returns>
        Task<bool> EditAsync(Expression<Func<TEntiry, bool>> columns, Expression<Func<TEntiry, bool>> func);
        /// <summary>
        /// 根据id查找数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task<TEntiry> FindAsync(int id);
        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="func">表达式树</param>
        /// <returns></returns>
        Task<TEntiry> FindAsync(Expression<Func<TEntiry, bool>> func);
        /// <summary>
        /// 查询全部数据
        /// </summary>
        /// <returns></returns>
        Task<List<TEntiry>> QueryAsync();
        Task<List<dynamic>> QueryAsyncDynamic();
        /// <summary>
        /// 自定义条件查询,表达式树可传入lambda表达式
        /// </summary>
        /// <param name="func"></param>
        /// <returns></returns>
        Task<List<TEntiry>> QueryAsync(Expression<Func<TEntiry, bool>> func);
        Task<List<dynamic>> QueryAsync(Expression<Func<TEntiry, dynamic>> expression, Expression<Func<TEntiry, bool>> func);
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <param name="total">返回到前端的数据量</param>
        /// <returns></returns>
        Task<List<TEntiry>> QueryAsync(int page, int size, RefAsync<int> total);
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="pageRequest">分页请求</param>
        /// <param name="total">返回的数据量</param>
        /// <returns></returns>
        Task<List<TEntiry>> QueryAsync(PageRequest pageRequest, RefAsync<int> total);
        /// <summary>
        /// 自定义条件分页查询
        /// </summary>
        /// <param name="func"></param>
        /// <param name="page"></param>
        /// <param name="size"></param>
        /// <param name="total"></param>
        /// <returns></returns>
        Task<List<TEntiry>> QueryAsync(Expression<Func<TEntiry, bool>> func, int page, int size, RefAsync<int> total);
    }
}
